import http from '@/utils/request.js'

// 用户相关接口
export const userApi = {
  // 微信登录
  login: (code) => http.post('/api/auth/login', { code }),
  
  // 获取用户信息
  getUserInfo: () => http.get('/api/user/info'),
  
  // 更新用户信息
  updateUserInfo: (data) => http.put('/api/user/info', data),
  
  // 获取用户余额
  getBalance: () => http.get('/api/user/balance'),
  
  // 获取邀请记录
  getInviteRecords: (params) => http.get('/api/user/invite-records', params),
  
  // 获取佣金记录
  getCommissionRecords: (params) => http.get('/api/user/commission-records', params)
}

// 商品相关接口
export const goodsApi = {
  // 获取首页推荐商品
  getHomeGoods: (params) => http.get('/api/goods/home', params),
  
  // 获取商品分类
  getCategories: () => http.get('/api/goods/categories'),
  
  // 获取分类商品列表
  getCategoryGoods: (params) => http.get('/api/goods/category', params),
  
  // 获取商品详情
  getGoodsDetail: (id) => http.get(`/api/goods/detail/${id}`),
  
  // 搜索商品
  searchGoods: (params) => http.get('/api/goods/search', params),
  
  // 获取限时秒杀商品
  getSeckillGoods: () => http.get('/api/goods/seckill'),
  
  // 获取团长推荐商品
  getLeaderGoods: (leaderId) => http.get(`/api/goods/leader/${leaderId}`)
}

// 购物车相关接口
export const cartApi = {
  // 获取购物车列表
  getCartList: () => http.get('/api/cart/list'),
  
  // 添加到购物车
  addToCart: (data) => http.post('/api/cart/add', data),
  
  // 更新购物车商品数量
  updateCartQuantity: (data) => http.put('/api/cart/update', data),
  
  // 删除购物车商品
  removeFromCart: (ids) => http.delete('/api/cart/remove', { ids }),
  
  // 清空购物车
  clearCart: () => http.delete('/api/cart/clear'),
  
  // 选择购物车商品
  selectCartItems: (data) => http.put('/api/cart/select', data)
}

// 订单相关接口
export const orderApi = {
  // 创建订单
  createOrder: (data) => http.post('/api/order/create', data),
  
  // 获取订单列表
  getOrderList: (params) => http.get('/api/order/list', params),
  
  // 获取订单详情
  getOrderDetail: (id) => http.get(`/api/order/detail/${id}`),
  
  // 取消订单
  cancelOrder: (id, reason) => http.put(`/api/order/cancel/${id}`, { reason }),
  
  // 确认收货
  confirmOrder: (id) => http.put(`/api/order/confirm/${id}`),
  
  // 申请退款
  applyRefund: (data) => http.post('/api/order/refund', data),
  
  // 支付订单
  payOrder: (data) => http.post('/api/order/pay', data)
}

// 团长相关接口
export const leaderApi = {
  // 获取团长信息
  getLeaderInfo: (id) => http.get(`/api/leader/info/${id}`),
  
  // 获取团长列表
  getLeaderList: (params) => http.get('/api/leader/list', params),
  
  // 获取团长订单
  getLeaderOrders: (params) => http.get('/api/leader/orders', params),
  
  // 接单
  acceptOrder: (id) => http.put(`/api/leader/accept-order/${id}`),
  
  // 拒单
  rejectOrder: (id, reason) => http.put(`/api/leader/reject-order/${id}`, { reason }),
  
  // 发货
  shipOrder: (id) => http.put(`/api/leader/ship-order/${id}`),
  
  // 获取佣金统计
  getCommissionStats: () => http.get('/api/leader/commission-stats'),
  
  // 获取佣金明细
  getCommissionDetails: (params) => http.get('/api/leader/commission-details', params),
  
  // 申请提现
  applyWithdraw: (data) => http.post('/api/leader/withdraw', data),
  
  // 申请成为团长
  applyLeader: (data) => http.post('/api/leader/apply', data)
}

// 邀请相关接口
export const inviteApi = {
  // 生成邀请海报
  generatePoster: () => http.get('/api/invite/poster'),
  
  // 获取邀请统计
  getInviteStats: () => http.get('/api/invite/stats'),
  
  // 获取邀请排行榜
  getInviteRanking: () => http.get('/api/invite/ranking'),
  
  // 获取邀请奖励
  getInviteRewards: () => http.get('/api/invite/rewards')
}

// 地址相关接口
export const addressApi = {
  // 获取地址列表
  getAddressList: () => http.get('/api/address/list'),
  
  // 添加地址
  addAddress: (data) => http.post('/api/address/add', data),
  
  // 更新地址
  updateAddress: (data) => http.put('/api/address/update', data),
  
  // 删除地址
  deleteAddress: (id) => http.delete(`/api/address/delete/${id}`),
  
  // 设置默认地址
  setDefaultAddress: (id) => http.put(`/api/address/default/${id}`)
}

// 优惠券相关接口
export const couponApi = {
  // 获取优惠券列表
  getCouponList: (params) => http.get('/api/coupon/list', params),
  
  // 领取优惠券
  receiveCoupon: (id) => http.post(`/api/coupon/receive/${id}`),
  
  // 获取我的优惠券
  getMyCoupons: (params) => http.get('/api/coupon/my', params),
  
  // 使用优惠券
  useCoupon: (id) => http.put(`/api/coupon/use/${id}`)
}

export default {
  userApi,
  goodsApi,
  cartApi,
  orderApi,
  leaderApi,
  inviteApi,
  addressApi,
  couponApi
} 